home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9097 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.6 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Data Name to Pointer Question
  5. Date: 6 Mar 1996 20:45:03 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4hlpkfINN15r@keats.ugrad.cs.ubc.ca>
  8. References: <4hkhtb$epm@theopolis.orl.mmc.com>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4hkhtb$epm@theopolis.orl.mmc.com>,
  12. Steve Woodcock <woodcock@escmail.orl.mmc.com> wrote:
  13. >   Over in the program itself, "process one" is a data structure filled
  14. >with information.
  15. >
  16. >   Is there a way for me to convert the string "process one" that I read
  17. >in from the data file to a pointer pointing to the actual structure
  18. >"process one"?  Essentially, I want to turn the contents of this string
  19. >variable into the *name* of the variable I want to access.
  20.  
  21. Not without incredible hackery that will render your program completely
  22. specific to a particular C implementation.
  23.  
  24. By the way "process one" is not a legal C identifier name because it contains
  25. whitespace.
  26.  
  27. What you _can_ do is store these structures in a list, and store a descriptive,
  28. unique name inside each structure. Then, do a lookup.
  29.  
  30. K&R2 shows you, by example and discussion, how to write a simple module for
  31. creating a binary search tree. You could insert your structures into such a
  32. tree, where the descriptive label is used as the lookup key.
  33.  
  34. Debugger programs can refer to variables by name, but they use debugging
  35. information to do this and are specific to particular environments/object
  36. formats. The method I suggest can be implemented using standard C.
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. >Steve
  45. >
  46. >+=============================================================================+
  47. >|                                                           _                 |
  48. >| Steven Woodcock                                     _____C .._.             |
  49. >| Senior Software Engineer, Gameware             ____/     \___/              |
  50. >| Lockheed Martin Information Systems Group     <____/\_---\_\    "Ferretman" |
  51. >| Phone:      719-597-5413                                                    |
  52. >| E-mail:     woodcock@escmail.orl.mmc.com (Work), swoodcoc@cris.com (Home)   |
  53. >| Web:        http://www.cris.com/~swoodcoc/ai.html    (Games AI page)        |
  54. >|             http://www.cris.com/~swoodcoc/steve.html (Boring Steve Stuff)   |
  55. >| Disclaimer: My opinions in NO way reflect the opinions of                   |
  56. >|             the Lockheed Martin Information Systems Group                   |
  57. >+=============================================================================+
  58.  
  59.  
  60. -- 
  61.  
  62.